package com.example.project.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.project.entity.Notice;

/**
 * 公告 数据层
 * 
 * @author ruoyi
 */
@Mapper
public interface NoticeMapper {
	
	/**
	 * 查询公告信息
	 * 
	 * @param noticeId 公告ID
	 * @return 公告信息
	 */
	@Select("select notice_id, notice_title, notice_type, cast(notice_content as char) as notice_content, status, create_by, create_time, update_by, update_time, remark from t_notice where notice_id = #{noticeId}")
	public Notice selectNoticeById(Long noticeId);

	/**
	 * 查询公告列表
	 * 
	 * @param notice 公告信息
	 * @return 公告集合
	 */
	@Select("<script>select notice_id, notice_title, notice_type, cast(notice_content as char) as notice_content, status, create_by, create_time, update_by, update_time, remark from t_notice <where><if test=\"noticeTitle != null and noticeTitle != ''\">AND notice_title like concat('%', #{noticeTitle}, '%')</if><if test=\"noticeType != null and noticeType != ''\">AND notice_type = #{noticeType}</if><if test=\"createBy != null and createBy != ''\">AND create_by like concat('%', #{createBy}, '%')</if></where></script>")
	public List<Notice> selectNoticeList(Notice notice);

	/**
	 * 新增公告
	 * 
	 * @param notice 公告信息
	 * @return 结果
	 */
	@Insert("<script>insert into t_notice (<if test=\"noticeTitle != null and noticeTitle != '' \">notice_title, </if><if test=\"noticeType != null and noticeType != '' \">notice_type, </if><if test=\"noticeContent != null and noticeContent != '' \">notice_content, </if><if test=\"status != null and status != '' \">status, </if><if test=\"remark != null and remark != ''\">remark,</if><if test=\"createBy != null and createBy != ''\">create_by,</if>create_time)values(<if test=\"noticeTitle != null and noticeTitle != ''\">#{noticeTitle}, </if><if test=\"noticeType != null and noticeType != ''\">#{noticeType}, </if><if test=\"noticeContent != null and noticeContent != ''\">#{noticeContent}, </if><if test=\"status != null and status != ''\">#{status}, </if><if test=\"remark != null and remark != ''\">#{remark},</if><if test=\"createBy != null and createBy != ''\">#{createBy},</if>sysdate())</script>")
	public int insertNotice(Notice notice);

	/**
	 * 修改公告
	 * 
	 * @param notice 公告信息
	 * @return 结果
	 */
	@Update("<script>update t_notice <set><if test=\"noticeTitle != null and noticeTitle != ''\">notice_title = #{noticeTitle}, </if><if test=\"noticeType != null and noticeType != ''\">notice_type = #{noticeType}, </if><if test=\"noticeContent != null\">notice_content = #{noticeContent}, </if><if test=\"status != null and status != ''\">status = #{status}, </if><if test=\"updateBy != null and updateBy != ''\">update_by = #{updateBy},</if>update_time = sysdate()</set> where notice_id = #{noticeId}</script>")
	public int updateNotice(Notice notice);

	/**
	 * 批量删除公告
	 * 
	 * @param noticeIds 需要删除的数据ID
	 * @return 结果
	 */
	@Delete("<script>delete from t_notice where notice_id in <foreach item=\"noticeId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">#{noticeId}</foreach></script>")
	public int deleteNoticeByIds(String[] noticeIds);
}